package cn.melon.view.admin.store;

import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import cn.melon.view.admin.store.ctr.StoreAddGoodsCtr;

public class AddGoodsDig extends JDialog {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private JTextField goodsId = new JTextField("",20);
    private JTextField goodsName = new JTextField("",20);
    private JTextField goodsType = new JTextField("",20);
    private JTextField goodsPrice = new JTextField("",20);
    private JTextField goodsDescription = new JTextField("",20);
    private JTextField goodsSales = new JTextField("",20);
//    private JTextField isSoldOut;

    
    ActionListener listener = new StoreAddGoodsCtr(this);
    
    private JButton saveButton;
    private JButton cancelButton;
    String[] textStr = {"商品编号：","商品名称：","商品类别：","商品价格：","商品描述：","商品销量："};
    
    JTextField[] jTextFields = {goodsId,goodsName,goodsType,goodsPrice,goodsDescription,goodsSales};
    public AddGoodsDig() {
//        super(owner);Dialog owner
        initialize();
    }
    private void initialize(){
        this.setTitle("添加商品");
        this.setSize(400, 300);
       
        JPanel panel = new JPanel();
        
        GridBagLayout layout = new GridBagLayout();

        panel.setLayout(layout);
        
        GridBagConstraints constraints = new GridBagConstraints();
        constraints.anchor = GridBagConstraints.EAST;
        constraints.fill = GridBagConstraints.NONE;
        constraints.weightx = 100;
        constraints.weighty = 100;
        for(int i=0;i<textStr.length;i++){

            constraints.gridx = 0;
            constraints.gridy = i;
            panel.add(new JLabel(textStr[i]),constraints);
            constraints.anchor = GridBagConstraints.CENTER;
            constraints.gridx = 1;
            panel.add(jTextFields[i],constraints);
            constraints.anchor = GridBagConstraints.EAST;
            constraints.gridx = 2;
            panel.add(Box.createRigidArea(new Dimension(2, 15)));
        }
        
        JPanel tPanel = new JPanel();
        constraints.anchor = GridBagConstraints.CENTER;
        constraints.gridx = 1;
        constraints.gridy = textStr.length;
        saveButton = new JButton("确定");
        cancelButton = new JButton("取消");
        saveButton.addActionListener(listener);
        cancelButton.addActionListener(listener);
        tPanel.add(saveButton);     //按钮
        tPanel.add(Box.createRigidArea(new Dimension(10, 15)));
        tPanel.add(cancelButton);
        panel.add(tPanel,constraints);      //按钮
        

        
        this.add(panel);
        this.setResizable(false);
    }
    
    public String getGoodsId(){
        return goodsId.getText();
    }
    
    public String getGoodsName() {
        return goodsName.getText();
    }


    public double getGoodsPrice() {
        return Double.parseDouble(goodsPrice.getText());
    }


    public String getGoodsType() {
        return goodsType.getText();
    }


    public String getGoodsDescription() {
        return goodsDescription.getText();
    }


    public long getGoodsSales() {
        return Long.parseLong(goodsSales.getText());
    }

//
//    public boolean isSoldOut() {
////        return isSoldOut;
//    }

    public static void main(String[] args) {
        Dialog dialog = new AddGoodsDig();
        dialog.setVisible(true);
    }
}
